#ifndef _RENZO_RESOURCE_MANAGER_
#define _RENZO_RESOURCE_MANAGER_

#include "RenzoMustHave.h"
#include <map>
using namespace std;

//#include <hash_map>
//using namespace stdext;

namespace Renzo
{
/*
 The global resource manager. ResourceManager object holds pointers to specific managers, e.g., MemoryManager, ImageManager, TextureManager.
 ResourceManager generates a unique ID for every resource loaded into Renzoderer system. 
 Query: Given a resource ID. Determine the existence of the resource in the system. Determine the type of resource. Retrieve the pointer to that resource.
 */
class RENZODERER_API ResourceManager
{
public:
	ResourceManager(void);
	~ResourceManager(void);

public:
	ResourceID genResourceID(ObjectType type);
	
protected:
	//std::map<ResourceType, ResourceIndex> maxIndices;	// store maximum indices of each resource type
	ResourceIndex maxIndices[NB_RESOURCE_TYPES];
protected:
	ImageManager* imageManager;

protected:
	///
	/// Object creator function
	///
	typedef Object*(*CreateFunc)(void);
	void	registerCreateFunc(ObjectType t, CreateFunc f);
public:
	void	registerCreateFuncs();

public:
	/**
	 Factory method to create objects
	 */
	Object* createObject(ObjectType t);
	void	disposeObject(Object* obj);
	void	disposeAll();
	Object* getObject(const ResourceID& id);
	Object* getObjectByName(const String& name);

protected:
	///
	/// Global object hash table allows object query by id.
	///	
	typedef map<ResourceID, Object*> ObjectMap;
	ObjectMap objectMap;
	///
	/// Creator of objects registered by ObjectType.
	///
	typedef map<ObjectType, CreateFunc> CreateFuncMap;
	CreateFuncMap createFuncMap;
	
protected:
	///
	/// Attach/detach function are protected and used internally. 
	///
	void attachObject(Object* obj);	
	void detachObject(Object* obj);
	void detachObject(const ResourceID& id);

};
}

#endif